package com.example.admin.androidtest.designmodel;

/**
 * Created by admin on 2017/12/25.
 */

public class SingletonClass {
    //1
//    private static class SingletonClassInstance {
//        private  static SingletonClass instance = new SingletonClass();
//    }
//
//    public static SingletonClass getInstance() {
//        return SingletonClassInstance.instance;
//    }

    //2
    private volatile static SingletonClass instance;

    public static SingletonClass getInstance() {

        if (instance == null) {
            synchronized (SingletonClass.class) {
                if (instance == null) {
                    instance = new SingletonClass();
                }
            }
        }
        return instance;
    }
}
